package com.jh.channel.pojo.fastsilver;

import net.sf.json.JSONObject;
import org.apache.commons.collections.MapUtils;

import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import static org.springframework.util.StringUtils.hasText;

public class FastSilverInternalView {

    public Map<String,String> addMap() {
        Map<String, String> pram = new HashMap<>();
        String orderNo = String.valueOf(System.currentTimeMillis());
        setOrderNo(orderNo);
        pram.put("order_id",orderNo);
        pram.put("address",getAddress());
        pram.put("agent_id",getAgentId());
        pram.put("area",getArea());
        pram.put("artif_identity",getIdCard());
        pram.put("artif_name",getArtifName());
        pram.put("artif_phone",getArtifPhone());
        pram.put("bank_add_no",getBankAddNo());
        pram.put("bank_address",getBankAddress());
        pram.put("bank_name",getBankName());
        pram.put("business_type",getBusinessType());
        pram.put("card",getCard());
        pram.put("card_name",getCardName());
        pram.put("card_phone",getCardPhone());
        pram.put("city",getCity());
        pram.put("classify",getClassify());
        pram.put("email",getEmail());
        pram.put("identity",getBankIdCard());
        pram.put("licence_begin_date",getLicenceBeginDate());
        pram.put("licence_expire_date",getLicenceExpireDate());
        pram.put("licence_no",getLicenceNo());
        pram.put("shop_keeper",getMerchantName());
        pram.put("shop_nickname",getNickname());
        pram.put("shop_name",getShopName());
        pram.put("shop_address",getShopAddress());
        pram.put("shop_phone",getShopPhone());
        pram.put("keeper_phone",getPhone());
        pram.put("notify_url",getNotifyUrl());
        pram.put("province",getProvince());
        pram.put("rate_alipay","0.0038");
        pram.put("rate_wx","0.0038");
        pram.put("type",getType());
        return pram;
    }

    public void toMap(Map<String,String> pram) {
        String orderNo = String.valueOf(System.currentTimeMillis());
        setOrderNo(orderNo);
        setUserId(MapUtils.getString(pram,"userId"));
        setShopName(MapUtils.getString(pram,"shopName"));
        setNickname(MapUtils.getString(pram,"nickname"));
        setMerchantName(MapUtils.getString(pram,"merchantName"));
        setPhone(MapUtils.getString(pram,"phone"));
        setShopPhone(MapUtils.getString(pram,"shopPhone"));
        setShopAddress(MapUtils.getString(pram,"shopAddress"));
        setEmail(MapUtils.getString(pram,"email"));
        setProvince(MapUtils.getString(pram,"province"));
        setCity(MapUtils.getString(pram,"city"));
        setArea(MapUtils.getString(pram,"shopAreas"));
        setAddress(MapUtils.getString(pram,"address"));
        setBusinessType(MapUtils.getString(pram,"businessType"));
        setLicenceNo(MapUtils.getString(pram,"licenceNo"));
        setLicenceBeginDate(MapUtils.getString(pram,"licenceBeginDate"));
        setLicenceExpireDate(MapUtils.getString(pram,"licenceExpireDate"));
        setArtifName(MapUtils.getString(pram,"artifName"));
        setArtifPhone(MapUtils.getString(pram,"artifPhone"));
        setIdCard(MapUtils.getString(pram,"idCard"));
        setRateWx(MapUtils.getString(pram,"rateWx"));
        setRateAlipay(MapUtils.getString(pram,"rateAlipay"));
        setCardName(MapUtils.getString(pram,"cardName"));
        setCard(MapUtils.getString(pram,"card"));
        setCardPhone(MapUtils.getString(pram,"cardPhone"));
        setBankName(MapUtils.getString(pram,"bankName"));
        setBankAddress(MapUtils.getString(pram,"bankAddress"));
        setBankAddNo(MapUtils.getString(pram,"bankAddNo"));
        setBankIdCard(MapUtils.getString(pram,"bankIdCard"));
        setClassify(MapUtils.getString(pram,"classify"));
        setType(MapUtils.getString(pram,"type"));
        String result = MapUtils.getString(pram,"fastSilverUpload");;

        Map<String,String> map = JSONObject.fromObject(result);
        FastSilverUpload fastSilverUpload = new FastSilverUpload();
        fastSilverUpload.setBussiness(MapUtils.getString(map,"bussiness"));
        fastSilverUpload.setOtherPhoto(MapUtils.getString(map,"otherPhoto"));
        fastSilverUpload.setOtherPhoto2(MapUtils.getString(map,"otherPhotoTwo"));
        fastSilverUpload.setOtherPhoto3(MapUtils.getString(map,"otherPhotoThree"));
        fastSilverUpload.setOtherPhoto4(MapUtils.getString(map,"otherPhotoFour"));
        fastSilverUpload.setIdentityBody(MapUtils.getString(map,"identityBody"));
        fastSilverUpload.setIdentityBack(MapUtils.getString(map,"identityBack"));
        fastSilverUpload.setIdentityBackCopy(MapUtils.getString(map,"identityBackCopy"));
        fastSilverUpload.setIdentityFace(MapUtils.getString(map,"identityFace"));
        fastSilverUpload.setIdentityFaceCopy(MapUtils.getString(map,"identityFaceCopy"));
        fastSilverUpload.setBussinessCard(MapUtils.getString(map,"bussinessCard"));
        fastSilverUpload.setMerchantCheck(MapUtils.getString(map,"merchantCheck"));
        fastSilverUpload.setMerchantHead(MapUtils.getString(map,"merchantHead"));
        setFastSilverUpload(fastSilverUpload);
    }

    public void addMap(Map<String,String> map) {

        String orderNo = String.valueOf(System.currentTimeMillis());
        setOrderNo(orderNo);
        String or = MapUtils.getString(map,"order_id");
        if (hasText(or)) {
            orderNo = or;
        }
        setMerchantId(MapUtils.getString(map,"shop_id"));
        setOrderNo(orderNo);
        setShopName(MapUtils.getString(map,"shop_name"));
        setNickname(MapUtils.getString(map,"shop_nickname"));
        setMerchantName(MapUtils.getString(map,"shop_keeper"));
        setPhone(MapUtils.getString(map,"keeper_phone"));
        setShopPhone(MapUtils.getString(map,"shop_phone"));
        setEmail(MapUtils.getString(map,"email"));
        setProvince(MapUtils.getString(map,"province"));
        setCity(MapUtils.getString(map,"city"));
        setArea(MapUtils.getString(map,"area"));
        setShopAddress(MapUtils.getString(map,"shop_address"));
        setBusinessType(MapUtils.getString(map,"business_type"));
        setLicenceNo(MapUtils.getString(map,"licence_no"));
        setLicenceBeginDate(MapUtils.getString(map,"licence_begin_date"));
        setLicenceExpireDate(MapUtils.getString(map,"licence_expire_date"));
        setArtifName(MapUtils.getString(map,"artif_name"));
        setArtifPhone(MapUtils.getString(map,"artif_phone"));
        setIdCard(MapUtils.getString(map,"artif_identity"));
        setRateWx(MapUtils.getString(map,"rate_wx"));
        setRateAlipay(MapUtils.getString(map,"rate_alipay"));
        setCardName(MapUtils.getString(map,"card_name"));
        setCard(MapUtils.getString(map,"card"));
        setCardPhone(MapUtils.getString(map,"card_phone"));
        setBankName(MapUtils.getString(map,"bank_name"));
        setBankAddress(MapUtils.getString(map,"bank_address"));
        setBankAddNo(MapUtils.getString(map,"bank_add_no"));
        setBankIdCard(MapUtils.getString(map,"identity"));
        setType(String.valueOf(MapUtils.getInteger(map,"type")));
        setClassify(MapUtils.getString(map,"classify"));
    }

    private String userId;

    //商户进件单号
    private String orderNo;

    //商户全称
    private String shopName;

    //商户简称
    private String nickname;

    //商户姓名
    private String merchantName;

    //负责人电话
    private String phone;

    //客服电话
    private String shopPhone;

    //商户地址
    private String shopAddress;

    //邮箱
    private String email;

    //省
    private String province;

    //市
    private String city;

    //区/县
    private String area;

    //详细地址
    private String address;

    //商户类型
    private String businessType;

    //营业执照
    private String licenceNo;

    //证件开始时间
    private String licenceBeginDate;

    //证件到期时间
    private String licenceExpireDate;

    //法人姓名
    private String artifName;

    //法人手机号
    private String artifPhone;

    //法人身份证号
    private String idCard;

    //微信费率
    private String rateWx;

    //支付宝费率
    private String rateAlipay;

    //结算人姓名
    private String cardName;

    //结算卡号
    private String card;

    //结算人手机号
    private String cardPhone;

    //结算银行
    private String bankName;

    //结算开户行
    private String bankAddress;

    //结算联行号
    private String bankAddNo;

    //结算人身份证号
    private String bankIdCard;

    //经营范围
    private String type;

    //经营范围
    private String classify;

    //回调地址
    private String notifyUrl;

    //合作商号
    private String agentId;

    //注册状态
    @Enumerated(EnumType.STRING)
    private LoginStatus status;

    private String errorMsg;

    //商户号
    private String merchantId;

    private Date createTime;

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    private FastSilverUpload fastSilverUpload;

    public FastSilverUpload getFastSilverUpload() {
        return fastSilverUpload;
    }

    public void setFastSilverUpload(FastSilverUpload fastSilverUpload) {
        this.fastSilverUpload = fastSilverUpload;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getOrderNo() {
        return orderNo;
    }

    public void setOrderNo(String orderNo) {
        this.orderNo = orderNo;
    }

    public String getShopName() {
        return shopName;
    }

    public void setShopName(String shopName) {
        this.shopName = shopName;
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    public String getMerchantName() {
        return merchantName;
    }

    public void setMerchantName(String merchantName) {
        this.merchantName = merchantName;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getProvince() {
        return province;
    }

    public void setProvince(String province) {
        this.province = province;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getArea() {
        return area;
    }

    public void setArea(String area) {
        this.area = area;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getBusinessType() {
        return businessType;
    }

    public void setBusinessType(String businessType) {
        this.businessType = businessType;
    }

    public String getLicenceNo() {
        return licenceNo;
    }

    public void setLicenceNo(String licenceNo) {
        this.licenceNo = licenceNo;
    }

    public String getLicenceBeginDate() {
        return licenceBeginDate;
    }

    public void setLicenceBeginDate(String licenceBeginDate) {
        this.licenceBeginDate = licenceBeginDate;
    }

    public String getArtifName() {
        return artifName;
    }

    public void setArtifName(String artifName) {
        this.artifName = artifName;
    }

    public String getArtifPhone() {
        return artifPhone;
    }

    public void setArtifPhone(String artifPhone) {
        this.artifPhone = artifPhone;
    }

    public String getIdCard() {
        return idCard;
    }

    public void setIdCard(String idCard) {
        this.idCard = idCard;
    }

    public String getRateWx() {
        return rateWx;
    }

    public void setRateWx(String rateWx) {
        this.rateWx = rateWx;
    }

    public String getRateAlipay() {
        return rateAlipay;
    }

    public void setRateAlipay(String rateAlipay) {
        this.rateAlipay = rateAlipay;
    }

    public String getCardName() {
        return cardName;
    }

    public void setCardName(String cardName) {
        this.cardName = cardName;
    }

    public String getCard() {
        return card;
    }

    public void setCard(String card) {
        this.card = card;
    }

    public String getCardPhone() {
        return cardPhone;
    }

    public void setCardPhone(String cardPhone) {
        this.cardPhone = cardPhone;
    }

    public String getBankName() {
        return bankName;
    }

    public void setBankName(String bankName) {
        this.bankName = bankName;
    }

    public String getBankAddress() {
        return bankAddress;
    }

    public void setBankAddress(String bankAddress) {
        this.bankAddress = bankAddress;
    }

    public String getBankAddNo() {
        return bankAddNo;
    }

    public void setBankAddNo(String bankAddNo) {
        this.bankAddNo = bankAddNo;
    }

    public String getBankIdCard() {
        return bankIdCard;
    }

    public void setBankIdCard(String bankIdCard) {
        this.bankIdCard = bankIdCard;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getClassify() {
        return classify;
    }

    public void setClassify(String classify) {
        this.classify = classify;
    }

    public String getNotifyUrl() {
        return notifyUrl;
    }

    public void setNotifyUrl(String notifyUrl) {
        this.notifyUrl = notifyUrl;
    }

    public String getAgentId() {
        return agentId;
    }

    public void setAgentId(String agentId) {
        this.agentId = agentId;
    }

    public LoginStatus getStatus() {
        return status;
    }

    public void setStatus(LoginStatus status) {
        this.status = status;
    }

    public String getMerchantId() {
        return merchantId;
    }

    public void setMerchantId(String merchantId) {
        this.merchantId = merchantId;
    }

    public String getShopPhone() {
        return shopPhone;
    }

    public void setShopPhone(String shopPhone) {
        this.shopPhone = shopPhone;
    }

    public String getShopAddress() {
        return shopAddress;
    }

    public void setShopAddress(String shopAddress) {
        this.shopAddress = shopAddress;
    }

    public String getLicenceExpireDate() {
        return licenceExpireDate;
    }

    public void setLicenceExpireDate(String licenceExpireDate) {
        this.licenceExpireDate = licenceExpireDate;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    public FastSilverInternal transform() throws ParseException {
        FastSilverInternal internal = new FastSilverInternal();
        internal.setOrderNo(getOrderNo());
        internal.setAddress(getShopAddress());
        internal.setAgentId(getAgentId());
        internal.setArea(getArea());
        internal.setIdCard(getIdCard());
        internal.setArtifName(getArtifName());
        internal.setBankAddNo(getBankAddNo());
        internal.setBankAddress(getBankAddress());
        internal.setBankName(getBankName());
        internal.setBusinessType(getBusinessType());
        internal.setArtifPhone(getArtifPhone());
        internal.setCard(getCard());
        internal.setCardName(getCardName());
        internal.setCardPhone(getCardPhone());
        internal.setCity(getCity());
        internal.setClassify(getClassify());
        internal.setEmail(getEmail());
        if (hasText(getLicenceBeginDate())) {
            internal.setLicenceBeginDate(getLicenceBeginDate());
        }
        if (hasText(getLicenceBeginDate())) {
            internal.setLicenceExpireDate(getLicenceBeginDate());
        }
        internal.setLicenceNo(getLicenceNo());
        internal.setBankIdCard(getBankIdCard());
        internal.setMerchantId(getMerchantId());
        internal.setMerchantName(getMerchantName());
        internal.setNickname(getNickname());
        internal.setPhone(getPhone());
        internal.setProvince(getProvince());
        internal.setRateAlipay(getRateAlipay());
        internal.setRateWx(getRateWx());
        internal.setShopName(getShopName());
        internal.setShopAddress(getShopAddress());
        internal.setShopPhone(getShopPhone());
        internal.setStatus(getStatus());
        internal.setType(getType());
        internal.setAddress(getAddress());
        internal.setUserId(getUserId());
        internal.setCreateTime(new Date());
        internal.setUpdateTime(new Date());
        return internal;
    }

    public void transform(FastSilverInternal internal) throws ParseException{
        setOrderNo(internal.getOrderNo());
        setAddress(internal.getAddress());
        setAgentId(internal.getAgentId());
        setArea(internal.getArea());
        setIdCard(internal.getIdCard());
        setArtifName(internal.getArtifName());
        setBankAddNo(internal.getBankAddNo());
        setBankAddress(internal.getBankAddress());
        setBankName(internal.getBankName());
        setBusinessType(internal.getBusinessType());
        setArtifPhone(internal.getArtifPhone());
        setCard(internal.getCard());
        setCardName(internal.getCardName());
        setCardPhone(internal.getCardPhone());
        setCity(internal.getCity());
        setClassify(internal.getClassify());
        setEmail(internal.getEmail());
        setLicenceBeginDate(String.valueOf(internal.getLicenceBeginDate()));
        setLicenceExpireDate(String.valueOf(internal.getLicenceBeginDate()));
        setLicenceNo(internal.getLicenceNo());
        setBankIdCard(internal.getBankIdCard());
        setMerchantId(internal.getMerchantId());
        setMerchantName(internal.getMerchantName());
        setNickname(internal.getNickname());
        setPhone(internal.getPhone());
        setProvince(internal.getProvince());
        setRateAlipay(internal.getRateAlipay());
        setRateWx(internal.getRateWx());
        setShopName(internal.getShopName());
        setStatus(internal.getStatus());
        setType(internal.getType());
        setUserId(internal.getUserId());
        setShopAddress(internal.getShopAddress());
        setShopPhone(internal.getShopPhone());
        setCreateTime(internal.getCreateTime());
        setErrorMsg(internal.getErrorMsg());
    }

}
